package com.yml.mall.vo;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.util.List;

/**
 * @ClassName ProductPage
 * @Author Administrator
 * @Date 2020/4/10   11:32
 */
@Data
@EqualsAndHashCode
@ToString
public class PageDTO<T> {

    //页数从1开始
    int pageNum;

    int pageSize;

    long totalItem;

    long totalPage;

    boolean hasPro;

    boolean hasNext;

    List<T> list;

    public PageDTO(int pageNum, int pageSize, long totalItem){
        this.pageSize=pageSize;
        this.totalItem=totalItem;
        totalPage=pageSize<=0?1:totalItem/pageSize;

        if(pageSize>0 && totalItem%pageSize>0) totalPage++;
        this.pageNum= Math.toIntExact(pageNum > totalPage ? totalPage : pageNum <= 0 ? 1 : pageNum);
        if(pageNum>=1 && pageNum <=totalPage){
            if(pageNum>1) hasPro=true;
            if(pageNum<totalPage) hasNext=true;
        }
    }

    public PageDTO(int pageNum, int pageSize, long totalItem,List<T> list){
        this(pageNum,  pageSize, totalItem);
        this.list=list;
    }
}
